Product Code Database
Example Keywords: ornament -dungeon $20
barcode-scavenger
   » » Wiki: Lexical Grammar
Tag Wiki 'Lexical Grammar'.
Tag

Lexical grammar
 (

 C O N T E N T S 

In , a lexical grammar or lexical structure is a defining the syntax of tokens. The program is written using characters that are defined by the lexical structure of the language used. The character set is equivalent to the alphabet used by any written language. The lexical grammar lays down the rules governing how a character sequence is divided up into subsequences of characters, each part of which represents an individual token. This is frequently defined in terms of regular expressions.

(2025). 9780070669086, Tata McGraw-Hill Education. .

For instance, the lexical grammar for many programming languages specifies that a starts with a character and continues until a matching is found ( makes this more complicated), that an identifier is an sequence (letters and digits, usually also allowing underscores, and disallowing initial digits), and that an is a sequence of digits. So in the following character sequence the tokens are string, identifier and number (plus whitespace tokens) because the space character terminates the sequence of characters forming the identifier. Further, certain sequences are categorized as keywords – these generally have the same form as identifiers (usually alphabetical words), but are categorized separately; formally they have a different token type.

(2025). 9780201310085, Addison-Wesley Professional. .


Examples
Regular expressions for common lexical rules follow (for example, C).

Unescaped string literal (quote, followed by non-quotes, ending in a quote):

"[^"]*"
     

Escaped string literal (quote, followed by escaped characters or non-quotes, ending in a quote):

"(\.|[^\"])*"
     

Integer literal:

[0-9]+
     

Decimal integer literal (no leading zero):

[1-9][0-9]*|0
     

Hexadecimal integer literal:

0[Xx][0-9A-Fa-f]+
     

Octal integer literal:

0[0-7]+
     

Identifier:

[A-Za-z_$][A-Za-z0-9_$]*
     


See also


External links

Page 1 of 1
1
Page 1 of 1
1

Account

Social:
Pages:  ..   .. 
Items:  .. 

Navigation

General: Atom Feed Atom Feed  .. 
Help:  ..   .. 
Category:  ..   .. 
Media:  ..   .. 
Posts:  ..   ..   .. 

Statistics

Page:  .. 
Summary:  .. 
1 Tags
10/10 Page Rank
5 Page Refs